from rest_framework import serializers
from .models import Area


class AreaSerializer(serializers.ModelSerializer):
    class Meta:
        model = Area
        fields = ['id','name']

#1个省  对多个市
class SubsAreaSerializer(serializers.ModelSerializer):
    # area-set = [Area,Area,Area]
    #默认反向关联的字段就是  关联模型类名小写—set
    #related-name  需要改变模型中的选项就可以
    #area-set=AreaSerializer（many=true,read-only=true）
    subs = AreaSerializer(many=True,read_only=True)

    class Meta:
        model = Area
        fields = ['id','name','subs']